package com.zmytest.controller;

import com.zmytest.dto.*;
import com.zmytest.service.AccountService;
import com.zmytest.service.PermissionService;
import com.zmytest.service.RoleService;
import com.zmytest.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created on 2018/12/19.
 *
 * @author zhangmingyu
 */
@RestController
@RequestMapping("/api")
public class BaseApiController {

    private final UserService userService;
    private final AccountService accountService;
    private final RoleService roleService;
    private final PermissionService permissionService;

    @Autowired
    public BaseApiController(UserService userService, AccountService accountService, RoleService roleService, PermissionService permissionService) {
        this.userService = userService;
        this.accountService = accountService;
        this.roleService = roleService;
        this.permissionService = permissionService;
    }


    @PostMapping("/user/create")
    public ResponseDto createUser(@RequestBody UserDto userDto){
        return userService.create(userDto);
    }
    @GetMapping("/user/find/{id}")
    public ResponseDto findUser(@PathVariable("id") Long id){
        return userService.find(id);
    }
    @PostMapping("/user/update")
    public ResponseDto updateUser(@RequestBody UserDto userDto){
        return userService.update(userDto);
    }
    @DeleteMapping("/user/delete/{id}")
    public ResponseDto deleteUser(@PathVariable("id") Long id){
        return userService.delete(id);
    }


    @PostMapping("/account/create")
    public ResponseDto createAccount(@RequestBody AccountDto accountDto){
        return accountService.create(accountDto);
    }
    @GetMapping("/account/find/{id}")
    public ResponseDto findAccount(@PathVariable("id") Long id){
        return accountService.find(id);
    }
    @PostMapping("/account/update")
    public ResponseDto updateAccount(@RequestBody AccountDto accountDto){
        return accountService.update(accountDto);
    }
    @DeleteMapping("/account/delete/{id}")
    public ResponseDto deleteAccount(@PathVariable("id") Long id){
        return accountService.delete(id);
    }


    @PostMapping("/role/create")
    public ResponseDto createRole(@RequestBody RoleDto roleDto){
        return roleService.create(roleDto);
    }

    @PostMapping("/permission/create")
    public ResponseDto createPermission(@RequestBody PermissionDto permissionDto){
        return permissionService.create(permissionDto);
    }
}
